xlv.obj.split={
	extend:function(){
	},
	implement:function(){
		this.implement('xlv.imp.dnd');
	},
	create:function(tag){
		var div=document.createElement((tag||'div'));
		div.setAttribute('xlvobject','xlv.obj.split');
		Element.addClassName(div,'class_split');
		return div;					 
	},
	properties:{
		overflowLastPane:'auto',
		continuousLayout:false
	},
	method:{
		construct:function(){
			Element.addClassName(this,'class_split');
		},
		initial:function(){
			this.dnd_properties.dragOnly=true;
			this.dnd_properties.ghost=!this.$P.continuousLayout;
			this.dnd_properties.ghostFloat=true;
			this.dnd_enabled(true);
			if(Prototype.Browser.IE)this.addEventHandler('resize','_resize');
			else Event.observe(window, 'resize', this.$V.resize=this._resize.bindAsEventListener(this), false);	
			this.layout();
		},
		layout:function(refresh){
			this.$V.layout=false;
			if(this.isDisplayNone())return;
			this._runtimeSize();
			var height=parseFloat(this.style.height);
			if(!height||height==Number.Nan||refresh)this.style.height=this.getDimensions().height+'px';
			this.$V.layout=true;
		},
		message:function(memo){
			if(memo.type=='active_changed'&&xlv.util.isDescendantOf(this,memo.to)&&!this.$V.layout)
				this.layout();
		},
		dispose:function(){
			if(!Prototype.Browser.IE) Event.stopObserving(window,'resize',this.$V.resize);
		},
		findDivider:function(element){
			return xlv.util.findDirectChild((element||this),{id:/xlvid_split_vert|xlvid_split_horz/});
		},
		findLeftTop:function(div){
			return xlv.util.findPrevSibling(div,{id:'xlvid_split_pane'});
		},
		findRightBottom:function(div){
			return xlv.util.findNextSibling(div,{id:'xlvid_split_pane'});
		},
		isVertical:function(aD){
			return aD.id=='xlvid_split_vert';
		},
		_runtimeSize:function(split,offset){
			split=(split||this.findDivider());
			offset=(offset||0);
			var lt=this.findLeftTop(split);
			var rb=this.findRightBottom(split);
			var vert=this.isVertical(split);
			var ofp=split.offsetParent;
			var size=(vert)?ofp.clientWidth:ofp.clientHeight;
			var ltc=this.findDivider(lt);
			var rbc=this.findDivider(rb);
			if(ltc) Element.setStyle(lt,{border:'none'});
			Element.setStyle(lt,{overflow:'hidden'});
			if(rbc) Element.setStyle(rb,{border:'none'});
			Element.setStyle(rb,{overflow:'hidden'});
			if(vert){
				var ltw=lt.offsetWidth-(lt.offsetWidth-lt.clientWidth)+offset;
				var lth=ofp.clientHeight-(lt.offsetHeight-lt.clientHeight);
				var splitw=split.offsetWidth;//split.clientWidth;
				var splith=ofp.clientHeight-(split.offsetHeight-split.clientHeight);
				Element.setStyle(rb,{overflow:'hidden', float:'none'});
				var rbw=(size-offset-lt.offsetWidth-split.offsetWidth-(rb.offsetWidth-rb.clientWidth));
				var rbh=ofp.clientHeight-(rb.offsetHeight-rb.clientHeight);
				if(ltw>=0&&lth>=0&&splith>=0&&rbw>=0&&rbh>=0){
					Element.setStyle(rb,{width:'1px'});
					Element.setStyle(lt,{width:ltw+'px',height:lth+'px'});
					Element.setStyle(split,{width:splitw+'px',height:splith+'px'});
					Element.setStyle(rb,{width:rbw+'px',height:rbh+'px'});
				}
			}else{
				Element.setStyle(lt,{overflow:'hidden', float:'none'});
				Element.setStyle(rb,{overflow:'hidden', float:'none'});
				var ltw=ofp.clientWidth-(lt.offsetWidth-lt.clientWidth);
				var lth=lt.offsetHeight-(lt.offsetHeight-lt.clientHeight)+offset;
				var splitw=ofp.clientWidth-(split.offsetWidth-split.clientWidth);
				var splith=split.clientHeight;
				var rbw=ofp.clientWidth-(rb.offsetWidth-rb.clientWidth);
				var rbh=(size-offset-lt.offsetHeight-split.offsetHeight-(rb.offsetHeight-rb.clientHeight));
				if(ltw>=0&&lth>=0&&splith>=0&&rbw>=0&&rbh>=0){
					Element.setStyle(rb,{height:'1px'});
					Element.setStyle(lt,{width:ltw+'px',height:lth+'px'});
					Element.setStyle(split,{width:splitw+'px', height:splith+'px'});
					Element.setStyle(rb,{width:rbw+'px',height:rbh+'px'});
				}
			}
			if(ltc)	this._runtimeSize(ltc);
			else Element.setStyle(lt,{overflow:this.$P.overflowLastPane});
			if(rbc)this._runtimeSize(rbc);
			else Element.setStyle(rb,{overflow:this.$P.overflowLastPane});
		},
		_resize:function(e){
			var src=(e.srcElement||e.target);
			if(src==this||(!Prototype.Browser.IE && src==window)) {
				this.layout();
			}
		},
		//////////dnd override
		dnd_dragable:function(e){
			var src=(e.srcElement||e.target);
			var allow=/xlvid_split_vert|xlvid_split_horz/.test(src.id);
			if(allow && !this.$P.continuousLayout){
				this.dnd_properties.direction=this.isVertical(src)? 'horizontal':'vertical';
			}
			return allow ? src : null;
		},
		dnd_drag:function(e){
			var p=this.dnd_properties;
			var offp=p.source.offsetParent;
			var vert=this.isVertical(p.source);
			var lt=this.findLeftTop(p.source);
			var rb=this.findRightBottom(p.source);
			var lt_min=parseInt(Element.getStyle(lt,'min-height'));
			var rb_min=parseInt(Element.getStyle(rb,'min-height'));
			var offsetxy=(this.$P.continuousLayout)?p.offsetXY:[p._lastXY[0]-p._startXY[0],p._lastXY[1]-p._startXY[1]];
			var offset=(vert)?offsetxy[0]:offsetxy[1];
			var ok=(vert)?lt.offsetWidth+offset>lt_min && rb.offsetWidth-offset>rb_min:
						  lt.offsetHeight+offset>lt_min && rb.offsetHeight-offset>rb_min;
			if(this.$P.continuousLayout){
				 if(ok) this._runtimeSize(p.source,offset);
			}else{
				if(this.dnd_properties.ghostFloat=!ok) return 'cancel';
			}
			return '';
		},
		dnd_dragEnd:function(e){
			if(!this.$P.continuousLayout){
				var p=this.dnd_properties;
				if(p.dragCancel) return;
				this._runtimeSize(p.source, (this.isVertical(p.source))? p._lastXY[0]-p._startXY[0]:p._lastXY[1]-p._startXY[1]);
			}
		}
	}
};
